package nicg.st.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import nicg.st.entity.AddIndicatorVO;
import nicg.st.entity.BuildTreeVO;
import nicg.st.entity.ExpertVO;
import nicg.st.entity.IndicatorDetailPO;
import nicg.st.entity.MatrixBuildVO;
import nicg.st.entity.PieNeedVO;
import nicg.st.entity.SaveEditVO;
import nicg.st.service.IndicatorSystemService;
import nicg.st.util.Log;

/**
 * @author GeChen
 * @Description
 * @date 2019/11/3 23:05
 */
@RestController
@RequestMapping("/api/indicatorsystem")
public class IndicatorSystemController {
	@Autowired
	IndicatorSystemService indicatorSystemService;

	// 返回所有的指标体系
	@RequestMapping(value = "/allIndicatorSystem", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getAllIndicatorSystem() {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getAllIndicatorSystem();
	}

	// 返回指标体系的数量
	@RequestMapping(value = "/countIndicatorSystem", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorSystemCount() {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorSystemCount();
	}

	// 根据页数展示指标体系
	@RequestMapping(value = "/getIndicatorSystemByPage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorSystemByPage(int page) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorSystemByPage(page);
	}

	// 根据指标体系的id返回指标体系的名称
	@RequestMapping(value = "/getRootIndicatorNameByIndicatorId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getRootIndicatorNameByIndicatorId(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getRootIndicatorDetailByIndicatorId(indicatorId);
	}

	// 根据指标体系的id返回指标体系的树形结构
	@RequestMapping(value = "/getIndicatorSystemTreeVO", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorSystemTreeVO(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getTreeVOByIndicatorId(indicatorId);
	}

	// 根据指标体系的id返回指标体系的树形结构(带权重字符)
	@RequestMapping(value = "/getIndicatorSystemTreeVONeedContat", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorSystemTreeVONeedContat(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getTreeVOByIndicatorIdNeedContat(indicatorId);
	}

	// 根据指标体系的id返回指标体系的树形思维导图结构
	@RequestMapping(value = "/getIndicatorSystemTreeMindVO", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorSystemTreeMindVO(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getTreeMindVOByIndicatorId(indicatorId);
	}

	// 根据指标体系的id返回指标体系的详情
	@RequestMapping(value = "/getIndicatorSystemInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorInfoByIndicatorId(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorInfoById(indicatorId);
	}

	/**
	 * 根据指标体系的名称查看是否存在指标体系
	 * 
	 * @param name
	 * @return
	 */
	@RequestMapping(value = "/getIndicatorInfoByName", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorInfoByName(String name) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorInfoByName(name);
	}

	/**
	 * 将树形结构插入到数据库中
	 * 
	 * @param buildTreeVO
	 * @return
	 */
	@RequestMapping(value = "/insertNewIndicator", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String insertNewIndicator(@RequestBody BuildTreeVO buildTreeVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.insertIndicatorByTreeVO(buildTreeVO);
	}

	// 根据指标体系id查询需要打分表相关内容
	@RequestMapping(value = "/getStepVO", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getStepVOById(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getStepVOByIndicatorId(indicatorId);
	}

	// 根据专家的打分情况存储到数据库
	@RequestMapping(value = "/writeInScore", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String writeInScore(@RequestBody MatrixBuildVO matrixBuildVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.writeInScore(matrixBuildVO);
	}

	// 根据指标体系的ID返回一级饼形图数据
	@RequestMapping(value = "/getPieChart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getPieChartByIndicatorSystemId(int indicatorSystemId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getPieChartByIndicatorSystemId(indicatorSystemId);
	}

	// 根据指标体系的ID和指标体系的名称返回下一级的饼形图数据
	@RequestMapping(value = "/getPieChartByPieNeedVO", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getPieChartByPieNeedVO(@RequestBody PieNeedVO pieNeedVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		System.out.println(pieNeedVO + "/////////////");
		return indicatorSystemService.getPieChartByPieNeedVO(pieNeedVO);
	}

	// 根据指标体系的ID返回不带参数的指标体系的List
	@RequestMapping(value = "/getIndicatorEdit", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorEdit(@RequestParam Integer indicatorSystemId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorEdit(indicatorSystemId);
	}

	// 根据修改的List更新数据库
	@RequestMapping(value = "/changeRelativeWeight", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String changeRelativeWeight(@RequestBody List<IndicatorDetailPO> indicatorDetailPOS) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.updateRelativeWeightByList(indicatorDetailPOS);
	}

	// 根据expertName和indicatorSystemId判断是否进行过打分
	@RequestMapping(value = "/getExpertPOExist", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getExpertPOExist(@RequestBody ExpertVO expertVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getExpertPOExist(expertVO);
	}

	// 根据指标体系的名称返回指标体系信息
	@RequestMapping(value = "/getIndicatorBaseByName", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getIndicatorBaseByName(String indicatorName) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getIndicatorBaseByName(indicatorName);
	}

	/**
	 * 根据指标体系的id删除对应的指标体系
	 * 
	 * @param indicatorId
	 * @return
	 */
	@RequestMapping(value = "/deleteIndicatorInfos", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String deleteIndicatorInfos(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.deleteIndicatorInfosByIndicatorId(indicatorId);
	}

	// 根据指标体系明细的指标id返回编辑信息
	@RequestMapping(value = "/getEditVO", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getEditVOByIndicatorDetailId(int indicatorDetailId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getEditVOByIndicatorDetailId(indicatorDetailId);
	}

	@RequestMapping(value = "/getFH", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getFH() {
		return indicatorSystemService.getFH();
	}

	// 根据指标体系id返回该指标体系的根节点信息
	@RequestMapping(value = "/getRootByIndicatorId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getRootByIndicatorId(int indicatorId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getRootIndicatorDetailPOByIndicatorId(indicatorId);
	}

	// 根据每一个saveVO保存信息
	@RequestMapping(value = "/saveInfoBySaveEditVO", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String saveInfoBySaveEditVO(@RequestBody SaveEditVO saveEditVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.saveInfoBySaveEditVO(saveEditVO);
	}

	// 根据methodId得到该method的参数
	@RequestMapping(value = "/getParamsByMethodId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getParamsByMethodId(int methodId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.getParamsByMethodId(methodId);
	}

	// 根据每一个saveVO删除信息
	@RequestMapping(value = "/deleteInfoBySaveEditVO", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String deleteInfoBySaveEditVO(@RequestBody SaveEditVO saveEditVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.deleteInfoBySaveEditVO(saveEditVO);
	}

	// 新增指标体系
	@RequestMapping(value = "/addNewIndicator", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String addNewIndicator(@RequestBody AddIndicatorVO addIndicatorVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.insertNewIndicatorSystem(addIndicatorVO);
	}

	// 测试接口
	@RequestMapping(value = "/testException", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String test(int i) {
		return indicatorSystemService.test(i);
	}

	// 更改指定节点的计算方法
	@RequestMapping(value = "/changeMethod", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String changeMethod(@RequestBody SaveEditVO saveEditVO) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.changeMethod(saveEditVO);
	}

	/**
	 * 在某一节点下增加指标体系
	 * 
	 * @param indicatorDetailId
	 * @return
	 */
	@RequestMapping(value = "/addIndicator", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String addIndicator(int indicatorDetailId) {
		Log.printLog(this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName());
		return indicatorSystemService.addIndicator(indicatorDetailId);
	}
}